<div class="headertitle">
	<span class="header">Forums</span>
</div>

<?php foreach($forums as $forum): ?>
	<?php foreach($forum['SubForum'] as $subForum): ?>
		<?php
		if(!isset($subForum['Thread'][0]['title'])){
			$subForum['Thread'][0]['topic_count'] = 0;
			$subForum['Thread'][0]['title'] = '';
			$subForum['Thread'][0]['id'] = 0;
			$subForum['Thread'][0]['thread_id'] = 0;
			$subForum['Thread'][0]['lastpost'] = '';
			$subForum['Thread'][0]['User']['username'] = '';
		}
		?>
		<div class="forumview">
			<div class="homeTitle">
				<?php
					echo $this->Html->link($subForum['name'], array(
						"controller" => "subForums",
						"action" => "displayTopics",
						"id" => $subForum['id'],
						"slug" => Inflector::slug($subForum['name'], '-')
					));
				?>
			</div>
			<br /><?php echo $subForum['description']; ?><br /><br />

			<div style="float: right; width: 250px">
				<div style="width: 120px; float: left">Total Threads</div>
				<div style="float: left"><?php echo $subForum['topic_count']; ?></div>
			</div>

			<div style="width: 120px; float: left">Latest Thread:</div>
			<div style="width: 520px; float: left">
				<?php echo $this->Html->link($subForum['Thread'][0]['title'],
					array(
						"controller" => "threads",
						"action" => "view",
						"id" => ($subForum['Thread']['0']['thread_id'] == 0) ? $subForum['Thread'][0]['id'] : $subForum['Thread'][0]['thread_id'],
						"slug" => Inflector::slug($subForum['Thread'][0]['title'], '-')
					));
				?>
			</div>



			<div style="float: right; width: 250px">
				<div style="width: 120px; float: left">Total Posts</div>
				<div style="float: left"><?php echo $subForum['thread_count']; ?></div>
			</div>

			<div style="width: 120px; float: left">Latest User</div>
			<div style="width: 520px; float: left"><?php echo $subForum['Thread'][0]['LatestUser']['username']; ?></div>


			<div style="width: 120px; float: left">Date</div>
			<div style="width: 520px; float: left"><?php echo $subForum['Thread'][0]['latest_reply_created']; ?></div>

			<div style="clear: both"></div>
		</div>
	<?php endforeach; ?>
<?php endforeach; ?>